var gen="http://localhost:8080/zyx";
var search = null;

var sightsPriceMin =1;
var sightsPriceMax =1;
var sightsLevel=0;
var sightsType="1";
searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
// function sift(minPrice, maxPrice, level, type, pageNum) {
//     var params = {
//         "minPrice": minPrice,
//         "maxPrice": maxPrice,
//         "level": level,
//         "type": type
//     };
//     $(".sights").html("");
//     var url = gen+"/sights/page/" + pageNum;
//     $.get(
//         url,
//         params,
//         function (result) {
//             if (result.code === 200) {
//                 for (let i = 0; i < result.data.list.length; i++) {
//                     var contentHtml =
//                         `<a href="`+gen+`/sights/details/`+result.data.list[i].travelSightsId+`">
//                                 <div class="image">
//                                     <img src="` + result.data.list[i].travelSightsMainImg + `">
//                                 </div>
//                                 <div class="details">
//                                     <div class="info">
//                                         <h3>` + result.data.list[i].travelSightsName + `</h3>
//                                         <div class="tag">
//                                             <span>` + result.data.list[i].travelSightsLevel + `A景区</span>
//                                             <div class="score">
//                                                 <strong>` + result.data.list[i].travelSightsScore + `</strong>分
//                                             </div>
//
//                                         </div>
//                                         <p>`+result.data.list[i].travelSightsDescribe+`</p>
//                                     </div>
//                                     <div class="btn">
//                                         <div class="action">
//                                             <span>立即查看</span>
//                                         </div>
//
//                                     </div>
//                                 </div>
//                             </a>`
//                     $(".sights").append(contentHtml)
//                 }
//                 /*分页*/
//                 var sightstype = type;
//                 var pricemin = minPrice;
//                 var pricemax = maxPrice;
//                 var sightslv = level;
//                 layui.use('laypage', function(){
//                     var laypage = layui.laypage;
//                     //执行一个laypage实例
//                     laypage.render({
//                         elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
//                         ,count: result.data.total //数据总数，从服务端得到
//                         ,theme: '#38c4ff'
//                         ,limit: result.data.pageSize//每页显示
//                         ,curr: result.data.pageNum
//                         ,jump:function (obj,first){
//                             if (!first){
//                                 result.data.pageNum=obj.curr;
//                                 sift(pricemin,pricemax,sightslv,sightstype,result.data.pageNum);
//                             }
//                         }
//                     });
//                 });
//                 // var prePage = result.data.prePage;
//                 // var nextPage = result.data.nextPage;
//                 // var pageEle;
//                 //
//                 // if (!result.data.hasPreviousPage) {
//                 //     pageEle =
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>' +
//                 //         '<a href="javascript:sift(' + pricemin + ',' + pricemax + ',' + sightslv + ',' + sightstype + ',' + nextPage + ')">下一页</a>'
//                 //     $(".page").html(pageEle);
//                 // } else if (!result.data.hasNextPage) {
//                 //     pageEle = '' +
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<a href="javascript:sift(' + minPrice + ',' + maxPrice + ',' + level + ',' + type + ',' + prePage + ')">上一页</a>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>'
//                 //     $(".page").html(pageEle);
//                 // } else {
//                 //     pageEle = '' +
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<a href="javascript:sift(' + minPrice + ',' + maxPrice + ',' + level + ',' + type + ',' + prePage + ')">上一页</a>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>' +
//                 //         '<a href="javascript:sift(' + minPrice + ',' + maxPrice + ',' + level + ',' + type + ',' + nextPage + ')">下一页</a>'
//                 //     $(".page").html(pageEle);
//                 // }
//             }
//         },
//         "json"
//     )
// }
//景点筛选
document.querySelector(".sights-lists").onclick = function (event){
    var ele = event.target;
    if(ele.nodeName==="LI"){
        var ulEle = ele.parentElement;
        for (let i = 0; i < ulEle.length; i++) {
            if(ulEle[i].checked){
                ulEle[i].checked = false;
            }
        }
        ele.firstChild.checked = true;
        if(ele.innerText!="不限"){
            if(ele.parentElement.parentElement.previousElementSibling.id==0){
                sightsPriceMin=ele.children[1].innerText;
                sightsPriceMax=ele.children[2].innerText;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==1){
                sightsLevel=ele.children[1].innerText;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==2){
                sightsType=ele.innerText;
                if(sightsType=="寺庙"){
                    sightsType="寺庙"
                }else if(sightsType=="水上乐园"){
                    sightsType="水上乐园"
                }else {
                    sightsType="动物园"
                }
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
        }else {
            if(ele.parentElement.parentElement.previousElementSibling.id==0){
                sightsPriceMin=1;
                sightsPriceMax=1;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==1){
                sightsLevel=0;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==2){
                sightsType="1";
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
        }
    }else if(ele.nodeName === "INPUT"){
        var ulEle = ele.parentElement.parentElement;
        for (let i = 0; i < ulEle.length; i++) {
            if(ulEle[i].checked){
                ulEle[i].checked = false;
            }
        }
        ele.checked = true;
        var eleP=ele.parentElement;
        if(eleP.innerText!="不限"){
            if(eleP.parentElement.parentElement.previousElementSibling.id==0){
                sightsPriceMin=eleP.children[1].innerText;
                sightsPriceMax=eleP.children[2].innerText;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==1){
                sightsLevel=eleP.children[1].innerText;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==2){
                sightsType=eleP.innerText;
                if(sightsType=="寺庙"){
                    sightsType="寺庙"
                }else if(sightsType=="水上乐园"){
                    sightsType="水上乐园"
                }else {
                    sightsType="动物园"
                }
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
        }else {
            if(eleP.parentElement.parentElement.previousElementSibling.id==0){
                sightsPriceMin=1;
                sightsPriceMax=1;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==1){
                sightsLevel=0;
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==2){
                sightsType="1";
                // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
            }
        }
    }
}



var planPriceMin=-1;
var planPriceMax=-1;
var planPerNum=-1;
var planAllDays=-1;
// function siftPlan(minPrice, maxPrice, perNum, days, pageNum) {
//     var params = {
//         "minPrice": minPrice,
//         "maxPrice": maxPrice,
//         "perNum": perNum,
//         "days": days
//     };
//     $(".sights").html("");
//     var url = gen+"/plans/page/" + pageNum;
//     $.get(
//         url,
//         params,
//         function (result) {
//             if (result.code === 200) {
//                 for (let i = 0; i < result.data.list.length; i++) {
//                     var tp = result.data.list[i].itineraryPlan.itineraryDescribe;
//                     var tpList = tp.split(",");
//                     var contentHtml =`<a href="`+gen+`/bespoke/`+result.data.list[i].itineraryPlan.itineraryPlanId+`">
//                                 <div class="image">
//                                     <img src="`+ result.data.list[i].travelSights.travelSightsMainImg + `">
//                                     <span class="dingzhi"><span>自友行定制</span></span>
//                                 </div>
//                                 <div class="details">
//                                     <div class="info">
//                                         <h3>` + result.data.list[i].itineraryPlan.itineraryTitle + `</h3>
//                                         <div class="tag">`;
//                                             for(let j=0;j<tpList.length;j++){
//                                                 contentHtml+=`<span style="margin-right: 2px;">`+tpList[j]+`</span>`
//                                             }
//                                             contentHtml+=`
//
//                                         </div>
//                                         <p>`+result.data.list[i].travelSights.travelSightsDescribe+`</p>
//                                     </div>
//                                     <div class="btn">
//                                         <div class="action">
//                                             <span>立即定制</span>
//                                         </div>
//                                         <span class="it-price">
//                                             <b>￥</b>
//                                             <strong style="font-family: Arial">`+result.data.list[i].itineraryPlan.itineraryBudget+`</strong>
//                                             起
//                                         </span>
//                                     </div>
//                                 </div>
//                             </a>`;
//                     $(".sights").append(contentHtml)
//                 }
//                 /*分页*/
//                 var planpernum = perNum;
//                 var pricemin = minPrice;
//                 var pricemax = maxPrice;
//                 var plandays = days;
//                 layui.use('laypage', function(){
//                     var laypage = layui.laypage;
//                     //执行一个laypage实例
//                     laypage.render({
//                         elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
//                         ,count: result.data.total //数据总数，从服务端得到
//                         ,theme: '#38c4ff'
//                         ,limit: result.data.pageSize//每页显示
//                         ,curr: result.data.pageNum
//                         ,jump:function (obj,first){
//                             if (!first){
//                                 result.data.pageNum=obj.curr;
//                                 siftPlan(pricemin,pricemax,planpernum,plandays,result.data.pageNum);
//                             }
//                         }
//                     });
//                 });
//                 // var prePage = result.data.prePage;
//                 // var nextPage = result.data.nextPage;
//                 // var pageEle;
//                 //
//                 // if (!result.data.hasPreviousPage) {
//                 //     pageEle =
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>' +
//                 //         '<a href="javascript:siftPlan(' + pricemin + ',' + pricemax + ',' + planpernum + ',' + plandays + ',' + nextPage + ')">下一页</a>'
//                 //     $(".page").html(pageEle);
//                 // } else if (!result.data.hasNextPage) {
//                 //     pageEle = '' +
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<a href="javascript:siftPlan(' + pricemin + ',' + pricemax + ',' + planpernum + ',' + plandays + ',' + prePage + ')">上一页</a>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>'
//                 //     $(".page").html(pageEle);
//                 // } else {
//                 //     pageEle = '' +
//                 //         '<span>' + '共' + result.data.pages + '页/' + result.data.total + '条' + '</span>' +
//                 //         '<a href="javascript:siftPlan(' + pricemin + ',' + pricemax + ',' + planpernum + ',' + plandays + ',' + prePage + ')">上一页</a>' +
//                 //         '<span>' + '当前是第' + result.data.pageNum + '页' + '</span>' +
//                 //         '<a href="javascript:siftPlan(' + pricemin + ',' + pricemax + ',' + planpernum + ',' + plandays + ',' + nextPage + ')">下一页</a>'
//                 //     $(".page").html(pageEle);
//                 // }
//             }
//         },
//         "json"
//     )
// }
//方案筛选
document.querySelector(".plan-lists").onclick = function (event){
    var ele = event.target;
    if(ele.nodeName==="LI"){
        var ulEle = ele.parentElement;
        for (let i = 0; i < ulEle.length; i++) {
            if(ulEle[i].checked){
                ulEle[i].checked = false;
            }
        }
        ele.firstChild.checked = true;

        if(ele.innerText!="不限"){
            if(ele.parentElement.parentElement.previousElementSibling.id==3){
                planPerNum=ele.children[1].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==4){
                planPriceMin=ele.children[1].innerText;
                planPriceMax=ele.children[2].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==5){
                planAllDays=ele.children[1].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
        }else {
            if(ele.parentElement.parentElement.previousElementSibling.id==3){
                planPerNum=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==4){
                planPriceMin=-1;
                planPriceMax=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(ele.parentElement.parentElement.previousElementSibling.id==5){
                planAllDays=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
        }
        // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
    }else if(ele.nodeName === "INPUT"){
        var ulEle = ele.parentElement.parentElement;
        for (let i = 0; i < ulEle.length; i++) {
            if(ulEle[i].checked){
                ulEle[i].checked = false;
            }
        }
        ele.checked = true;
        var eleP=ele.parentElement;

        if(eleP.innerText!="不限"){
            if(eleP.parentElement.parentElement.previousElementSibling.id==3){
                planPerNum=eleP.children[1].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==4){
                planPriceMin=eleP.children[1].innerText;
                planPriceMax=eleP.children[2].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==5){
                planAllDays=eleP.children[1].innerText;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
        }else {
            if(eleP.parentElement.parentElement.previousElementSibling.id==3){
                planPerNum=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==4){
                planPriceMin=-1;
                planPriceMax=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
            if(eleP.parentElement.parentElement.previousElementSibling.id==5){
                planAllDays=-1;
                // siftPlan(planPriceMin,planPriceMax,planPerNum,planAllDays,1);
                searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
            }
        }
        // sift(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1);
    }
}

//双模块切换
document.querySelector(".sift-type").onclick = function (event){
    var ele = event.target;
    if(ele.nodeName ==="A" && ele.innerText ==="景点"){
        sightsPriceMin =1;
        sightsPriceMax =1;
        sightsLevel=0;
        sightsType="1";
        searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
        for (let i = 0; i < ele.parentElement.children.length; i++) {
            ele.parentElement.children[i].classList.remove('all-onclick');
        }
        ele.classList.add('all-onclick');
        var listEle = document.querySelector(".sights-lists");
        document.querySelector(".plan-lists").innerHTML=""
        listEle.innerHTML='<div class="list-item">\n' +
            '                <label id="0">门票价格区间：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox"><span class="min">0</span>-<span class="max">200</span></li>\n' +
            '                        <li><input type="checkbox"><span class="min">201</span>-<span class="max">400</span></li>\n' +
            '                        <li><input type="checkbox"><span class="min">401</span>-<span class="max">1000</span></li>\n' +
            '                    </form>\n' +
            '                </ul>\n' +
            '            </div>\n' +
            '            <div class="list-item">\n' +
            '                <label id="1">景点星级：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox"><span>1</span>星级</li>\n' +
            '                        <li><input type="checkbox"><span>2</span>星级</li>\n' +
            '                        <li><input type="checkbox"><span>3</span>星级</li>\n' +
            '                        <li><input type="checkbox"><span>4</span>星级</li>\n' +
            '                        <li><input type="checkbox"><span>5</span>星级</li>\n' +
            '                    </form>\n' +
            '\n' +
            '                </ul>\n' +
            '            </div>\n' +
            '            <div class="list-item">\n' +
            '                <label id="2">景点类型：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox">寺庙</li>\n' +
            '                        <li><input type="checkbox">水上乐园</li>\n' +
            '                        <li><input type="checkbox">动物园</li>\n' +
            '                    </form>\n' +
            '                </ul>\n' +
            '            </div>'
    }
    else if(ele.innerText ==="行程方案"){
        planPriceMin=-1;
        planPriceMax=-1;
        planPerNum=-1;
        planAllDays=-1;
        searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
        for (let i = 0; i < ele.parentElement.children.length; i++) {
            ele.parentElement.children[i].classList.remove('all-onclick');
        }
        ele.classList.add('all-onclick');
        var listEle = document.querySelector(".plan-lists");
        document.querySelector(".sights-lists").innerHTML=""
        listEle.innerHTML ='<div class="list-item">\n' +
            '                <label id="3">旅行人数：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox"><span>2</span>人</li>\n' +
            '                        <li><input type="checkbox"><span>3</span>人</li>\n' +
            '                        <li><input type="checkbox"><span>4</span>人</li>\n' +
            '                        <li><input type="checkbox"><span>5</span>人</li>\n' +
            '                    </form>\n' +
            '                </ul>\n' +
            '            </div>\n' +
            '            <div class="list-item">\n' +
            '                <label id="4">人均消费：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox"><span>100</span>-<span>200</span>元</li>\n' +
            '                        <li><input type="checkbox"><span>200</span>-<span>300</span>元</li>\n' +
            '                        <li><input type="checkbox"><span>300</span>-<span>400</span>元</li>\n' +
            '                        <li><input type="checkbox"><span>400</span>-<span>1000</span>元</li>\n' +
            '                    </form>\n' +
            '\n' +
            '                </ul>\n' +
            '            </div>\n' +
            '            <div class="list-item">\n' +
            '                <label id="5">旅游天数：</label>\n' +
            '                <ul>\n' +
            '                    <form>\n' +
            '                        <li><input type="checkbox" checked="checked">不限</li>\n' +
            '                        <li><input type="checkbox"><span>2</span>天</li>\n' +
            '                        <li><input type="checkbox"><span>3</span>天</li>\n' +
            '                        <li><input type="checkbox"><span>4</span>天</li>\n' +
            '                        <li><input type="checkbox"><span>5</span>天</li>\n' +
            '                    </form>\n' +
            '                </ul>\n' +
            '            </div>'
    }
}

//检索景点
function searchPlans(minPrice, maxPrice, perNum, days, pageNum,key){
    $(".sights").html("");
    var url = gen+"/search/ES/Plan/" + pageNum;
    $.get(
        url,
        {
            "minPrice": minPrice,
            "maxPrice": maxPrice,
            "perNum": perNum,
            "days":days,
            "key":key
        },
        function (result) {
            if (result.code === 200) {
                if(result.data.searchHits.length==0){
                    var contentHtml=`<div style="font-size: 14px;color: #38c4ff;">查不到啦</div>`
                    $(".sights").append(contentHtml)
                }
                for (let i = 0; i < result.data.searchHits.length; i++) {
                    var tp = result.data.searchHits[i].content.itineraryDescribe;
                    var tpList = tp.split(",");
                    var contentHtml =`<a href="`+gen+`/bespoke/`+result.data.searchHits[i].content.itineraryPlanId+`" target="_blank">
                                <div class="image">
                                    <img src="`+ result.data.searchHits[i].content.itineraryMainImg + `">
                                    <span class="dingzhi"><span>自友行定制</span></span>
                                </div>
                                <div class="details">
                                    <div class="info">
                                        <h3>` + result.data.searchHits[i].content.itineraryTitle + `</h3>
                                        <div class="tag">`;
                    for(let j=0;j<tpList.length;j++){
                        contentHtml+=`<span style="margin-right: 2px;">`+tpList[j]+`</span>`
                    }
                    contentHtml+=`
                                            
                                        </div>
                                        <p>`+result.data.searchHits[i].content.itineraryText+`</p>
                                    </div>
                                    <div class="btn">
                                        <div class="action">
                                            <span>立即定制</span>
                                        </div>
                                        <span class="it-price">
                                            <b>￥</b>
                                            <strong style="font-family: Arial">`+result.data.searchHits[i].content.itineraryBudget+`</strong>
                                            起
                                        </span>
                                    </div>
                                </div>
                            </a>`;
                    $(".sights").append(contentHtml)
                }
                /*分页*/
                var planpernum = perNum;
                var pricemin = minPrice;
                var pricemax = maxPrice;
                var plandays = days;
                var page = pageNum;
                layui.use('laypage', function(){
                    var laypage = layui.laypage;
                    //执行一个laypage实例
                    laypage.render({
                        elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                        ,count: result.data.totalHits //数据总数，从服务端得到
                        ,theme: '#38c4ff'
                        ,limit: 3//每页显示
                        ,curr: page
                        ,jump:function (obj,first){
                            if (!first){
                                page=obj.curr;
                                searchPlans(pricemin,pricemax,planpernum,plandays,page,search);
                            }
                        }
                    });
                });
            }
        },
        "json"
    )
}
//检索方案
function searchSights(minPrice, maxPrice, level, type, pageNum,key){
    $(".sights").html("");
    var url=gen+"/search/ES/"+pageNum;
    console.log(url)
    $.get(
        url,
        {
            "minPrice": minPrice,
            "maxPrice": maxPrice,
            "level": level,
            "type":type,
            "key":key
        },
        function (result){
            console.log(result)
            if (result.code === 200) {
                for (let i = 0; i < result.data.searchHits.length; i++) {
                    var strs = new Array();
                    var str = result.data.searchHits[i].content.travel_sights_main_img;
                    strs = str.split(",");
                    var mainImgUrl = strs[0];
                    var contentHtml =
                        `<a href="`+gen+`/sights/details/`+result.data.searchHits[i].content.travel_sights_id+`" target="_blank">
                                <div class="image">
                                    <img src="` + mainImgUrl + `">
                                </div>
                                <div class="details">
                                    <div class="info">
                                        <h3>` + result.data.searchHits[i].content.travel_sights_name + `</h3>
                                        <div class="tag">
                                            <span>` + result.data.searchHits[i].content.travel_sights_level + `A景区</span>
                                            <div class="score">
                                                <strong>` + result.data.searchHits[i].content.travel_sights_score + `</strong>分
                                            </div>

                                        </div>
                                        <p>`+result.data.searchHits[i].content.travel_sights_describe+`</p>
                                    </div>
                                    <div class="btn">
                                        <div class="action">
                                            <span>立即查看</span>
                                        </div>
                                
                                    </div>
                                </div>
                            </a>`
                    $(".sights").append(contentHtml)
                }
                /*分页*/
                var page=pageNum;
                layui.use('laypage', function(){
                    var laypage = layui.laypage;
                    //执行一个laypage实例
                    laypage.render({
                        elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                        ,count: result.data.totalHits //数据总数，从服务端得到
                        ,theme: '#38c4ff'
                        ,limit: 3//每页显示
                        ,curr: page
                        ,jump:function (obj,first){
                            if (!first){
                                page=obj.curr;
                                searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, page,search);
                            }
                        }
                    });
                });
            }
        },
        "json"
    )
}

$(".search-btn").click(function (){
    $(".sights").html("");
    search = $(".mudidi-input").val();
    var eleType = $(".sift-type")[0].children[0];
    if(eleType.innerText==="景点"){
        if(eleType.classList.length>1){
            searchSights(sightsPriceMin, sightsPriceMax, sightsLevel, sightsType, 1,search);
        }else {
            searchPlans(planPriceMin,planPriceMax,planPerNum,planAllDays,1,search);
        }
    }



})

$(".mudidi-input").on('keypress',function (event){
    if (event.keyCode===13){
        console.log(111)
        $(".search-btn").trigger('click')
    }
})